/*
 * @lc app=leetcode.cn id=1184 lang=javascript
 *
 * [1184] 公交站间的距离
 */

// @lc code=start
/**
 * @param {number[]} distance
 * @param {number} start
 * @param {number} destination
 * @return {number}
 */
var distanceBetweenBusStops = function(distance, start, destination) {
    let min=0
    if(start<destination){
       for(let i=start;i<destination;i++){
           min+=distance[i]
       } 
    }
    if(start>destination){
        for(let i=start-1;i>=destination;i--){
            min+=distance[i]
        }
    }
    let sum=0
    for(let i=0;i<distance.length;i++){
        sum+=distance[i]
    }
    return Math.min(min,sum-min)
};
// @lc code=end

